from rest_framework.generics import ListAPIView,CreateAPIView,ListCreateAPIView,RetrieveAPIView,UpdateAPIView,DestroyAPIView
from product.models import Product
from Apis.serializers import ProductModelSerializer
from rest_framework.permissions import IsAuthenticated
from rest_framework.authentication import BasicAuthentication
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter

class ProductGListMixin(ListAPIView,CreateAPIView):  # 继承ListAPIView类，用于获取所有数据。
    # # 认证用户
    # authentication_classes = [BasicAuthentication]
    # # 权限类
    # permission_classes = [IsAuthenticated]
    
    queryset = Product.objects.all()  # 接收的是查询之后的数据。
    serializer_class = ProductModelSerializer  # 接收的是序列化器类，用于序列化和反序列化数据。
    # 数据查询完了，再过滤数据
    # 配置过滤器后端
    filter_backends = [DjangoFilterBackend,OrderingFilter]  # 过滤    
    filterset_fields = ["product_name","price"]  # 过滤字段
    # 配置排序字段
    ordering_fields = ["id","price"]
    # 默认字段设置
    ordering = ["id"]
    
    
    
    
    
    